import java.util.Scanner;
//分汽水瓶
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextLine()){
            int n = sc.nextInt();
            if(n == 0) break;
            int result = solution(n);
            System.out.println(result);
        }
    }
    private static int solution(int n){
        int result = 0;
        while(n>=3){
            result += n/3;
            // 此时有的汽水瓶，是喝后换回来的 加 还没有喝的
            n = n/3 + n%3;
        }
        if(n==2){
            result++;
        }
        return result;    
    }
}
